<template>
  <div class="index-container">
    <div class="header">
      <div class="header-left">
        <img src="@/assets/images/logo.png" alt="" class="logo" />
        <div class="header-title">重庆依法治市智慧云平台</div>
      </div>
      <div class="header-right">
        <div class="right-time">{{ time }}</div>
        <div class="right-date">
          <div class="date-day">{{ day }}</div>
          <div class="date-week">星期{{ week }}</div>
        </div>
      </div>
    </div>
    <div class="nav-video">
      <swiper
        ref="swiper"
        class="swiper-container"
        :options="swiperOptions"
      >
        <swiper-slide
          v-for="(item, index) in data.banners"
          :key="index"
          class="swiper-slide"
        >
          <div @click="onClickBanner(index)" class="swiper-slide-content">
            <video ref="bannerRef" v-if="item.type == 2" :src="item.src" class="play-video"></video>
            <img ref="bannerRef" v-else  :src="item.src" class="play-video" alt="" />
            <img v-if="item.type == 2 && !playVideo" src="@/assets/images/play.png" class="play-icon" alt="">
          </div>
        </swiper-slide>
      </swiper>
      
    </div>
    <div class="content">
      <div class="nav-items">
        <div class="nav-item">
          <router-link to="/pageview?key=anli" class="nav-item nav1">
            <img src="@/assets/images/nav/n1.png" alt="" class="nav-icon" />
            <div class="nav-title">案例库</div>
          </router-link>
        </div>
        <div class="nav-item">
          <router-link to="/pageview?key=falvzy" class="nav-item nav1">
            <!-- <img src="@/assets/images/nav/nav7.png" alt="" class="nav-icon"> -->
            <img src="../../static/linkLogo/flzx.png" alt="" class="nav-icon" />
            <div class="nav-title">法律咨询</div>
          </router-link>
        </div>
        <div class="nav-item">
          <router-link to="/list?type=2" class="nav-item nav1">
            <!-- <img src="@/assets/images/nav/nav3.png" alt="" class="nav-icon"> -->
            <img src="../../static/linkLogo/flyz.png" alt="" class="nav-icon" />
            <div class="nav-title">法律援助</div>
          </router-link>
        </div>
        <!-- <div class="nav-item">
          <router-link to="/child2" class="nav-item nav1">
            <img src="@/assets/images/nav/n2.png" alt="" class="nav-icon">
            <div class="nav-title">智慧赔偿计算</div>
          </router-link>
        </div> -->
        <div class="nav-item">
          <router-link to="/child3" class="nav-item nav1">
            <img src="@/assets/images/nav/n5.png" alt="" class="nav-icon" />
            <div class="nav-title">更多法律服务</div>
          </router-link>
        </div>
        <div class="nav-item">
          <router-link to="/list?showPhone=1" class="nav-item nav1">
            <img src="@/assets/images/nav/n3.png" alt="" class="nav-icon" />
            <div class="nav-title">咨询热线</div>
          </router-link>
        </div>
        <!-- <div class="nav-item" @click="onClickBanner">
          <div class="nav-item nav1">
            <img src="@/assets/images/nav/n4.png" alt="" class="nav-icon">
            <div class="nav-title">政法视频</div>
          </div>
        </div> -->
      </div>
      <router-link to="/pageview?key=nm1" class="waist">
        农民工·欠薪求助绿色通道
      </router-link>
      <!-- <router-link to="/child1" class="waist">农民工·欠薪求助绿色通道</router-link> -->
      <div class="artice-module">
        <div class="left-newspaper">
          <router-link to="/pdfswiper">
            <img
              :src="data.newspaper.src"
              class="newspaper fullscreen"
              alt=""
            />
          </router-link>
        </div>
        <div class="right-artice">
          <router-link :to="{name: 'NewsDetail', query: {id: data.cover.newsId}}">
            <!-- <img src="@/assets/images/bz3.png" class="newspaper rightitem" alt=""> -->
            <img :src="data.cover.src" class="newspaper rightitem" alt="" />
          </router-link>
          <div class="artice-list">
            <div v-for="(item, i) in data.news" :key="i" class="artice-item">
              <router-link :to="{name: 'NewsDetail', query: {id: item.id}}">
                <div class="artice-title aline">{{ item.title }}</div>
                <div class="artice-time">{{ item.createTime }}</div>
              </router-link>
            </div>
          </div>
        </div>
      </div>
      <div class="link-list">
        <div class="link-item">
          <router-link to="/pageview?key=l2"
            ><img class="linkImg" src="../../static/linkLogo/zgpfw.png" alt=""
          /></router-link>
        </div>
        <div class="link-item">
          <router-link to="/pageview?key=l4"
            ><img class="linkImg" src="../../static/linkLogo/cqfzzx.jpg" alt=""
          /></router-link>
        </div>
        <div class="link-item">
          <router-link to="/pageview?key=l1"
            ><img class="linkImg" src="../../static/linkLogo/zgcaw.png" alt=""
          /></router-link>
        </div>
        <div class="link-item">
          <router-link to="/pageview?key=l6"
            ><img class="linkImg" src="../../static/linkLogo/fzw.png" alt=""
          /></router-link>
        </div>
      </div>
      <div class="link-list">
        <div class="link-item">
          <router-link to="/pageview?key=l5"
            ><img class="linkImg" src="../../static/linkLogo/cqrb.jpg" alt=""
          /></router-link>
        </div>
        <div class="link-item">
          <router-link to="/pageview?key=l7"
            ><img
              class="linkImg"
              src="https://dss1.bdstatic.com/6OF1bjeh1BF3odCf/it/u=2592792245,2647608677&fm=85&app=79&f=JPEG?w=121&h=75&s=0FE6ED16D5B45D90147DB9D600005031"
              alt=""
          /></router-link>
        </div>
        <div class="link-item">
          <router-link to="/pageview?key=l3"
            ><img class="linkImg" src="../../static/linkLogo/fxh.png" alt=""
          /></router-link>
        </div>
        <div class="link-item">
          <router-link to="/pageview?key=l8"
            ><img class="linkImg" src="../../static/linkLogo/zgfyw.png" alt=""
          /></router-link>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import moment from "moment";
import { Swiper, SwiperSlide } from "vue-awesome-swiper";
import "swiper/css/swiper.css";
import video1 from '../../static/video/1.mp4'
import video2 from '../../static/video/2.mp4'
export default {
  components: {
    Swiper,
    SwiperSlide,
  },
  data() {
    return {
      time: "",
      day: "",
      week: "",
      playVideo: false,
      current: 0,
      swiperOptions: {
        slidesPerView: 1,
        centeredSlides: true,
        spaceBetween: 0,
        autoplay: {
          delay: 30000,
          disableOnInteraction: false,
        },
        loop: true,
        on: {
          slideChangeTransitionStart: this.onChangeSlide
        }
      },
      data: {
        banners: [],
        cover: {},
        news: [],
        newspaper: {},
      },
      bannerType: 0,
    };
  },
  created() {
    this.getCurrData();
    setTimeout(() => {
      this.getCurrData();
    }, 1 * 60 * 1000);
    this.getData();
  },
  methods: {
    getCurrData() {
      const currDate = moment();
      this.time = currDate.format("HH:mm");
      this.day = currDate.format("yyyy年MM月DD日");
      const week = currDate.weekday();
      const weekMap = {
        1: "一",
        2: "二",
        3: "三",
        4: "四",
        5: "五",
        6: "六",
        7: "日",
      };
      this.week = weekMap[week];
    },
    getData() {
      this.$http.get("/home/").then(res => {
        this.data = Object.assign({}, this.data, res.data)
        this.$store.commit('SET_SCREEN_LIST', res.data.screenSave || [{src: 'https://ss1.bdstatic.com/70cFvXSh_Q1YnxGkpoWK1HF6hhy/it/u=3796178936,344163749&fm=26&gp=0.jpg'}])
      });
    },
    onClickBanner(i) {
      console.log(this.playVideo, this.$refs.bannerRef[i])
      !this.playVideo
        ? this.$refs.bannerRef[i].play()
        : this.$refs.bannerRef[i].pause()
      this.playVideo = !this.playVideo;
    },
    onChangeSlide() {
      // console.log('e', e,this.$refs.realIndex)
      // return
      // this.current = e.realIndex;
      // this.bannerType = this.data.banners[e.realIndex].type
      // this.$refs.bannerRef.forEach(n => {
      //   n.pause && n.pause()
      // })
      this.playVideo = false;
    },
  },
};
</script>

<style lang="less" scoped>
.index-container {
  width: 100%;
  background: url("../../static/linkLogo/backImg.png") 100% 100%;
  padding-bottom: 0.1rem;
  .header {
    background: rgb(156, 18, 13);
    height: 0.6rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.1rem;
    color: #fff;
    .header-left {
      display: flex;
      align-items: center;
      .logo {
        display: block;
        width: 0.38rem;
        margin-right: 0.1rem;
      }
      .header-title {
        font-size: 0.26rem;
        line-height: 1.3;
      }
    }
    .header-right {
      display: flex;
      align-items: center;
    }
    .right-time {
      font-size: 0.24rem;
      margin-right: 0.1rem;
    }
    .right-date {
      font-size: 0.12rem;
      line-height: 0.18rem;
      text-align: center;
    }
  }
  .nav-video {
    background: #ccc;
    position: relative;
    height: 6rem;
    .swiper-slide-content{
      position: relative;
    }
    .play-video {
      width: 100%;
      height: 6rem;
    }
    .play-icon {
      position: absolute;
      width: 1.6rem;
      height: 1.6rem;
      display: block;
      top: 50%;
      left: 50%;
      margin-top: -0.8rem;
      margin-left: -0.8rem;
      z-index: 2;
    }
  }
  .content {
    padding: 0.1rem;
  }
  .nav-lists {
    display: flex;
    .nav-list {
      width: 20%;
      & + .nav-list {
        margin-left: 0.1rem;
      }
      .nav-item {
        display: flex;
        align-items: center;
        height: 1.28rem;
        border-radius: 0.04rem;
        color: #fff;
        box-sizing: border-box;
        & + .nav-item {
          margin-top: 0.1rem;
        }
        &.nav1 {
          background: #5e7ad9;
        }
        &.nav2 {
          background: #d3ac1c;
        }
        &.nav3 {
          background: #309ebf;
        }
        &.nav4 {
          background: #449050;
        }
        &.nav5 {
          background: #3774c2;
        }
        &.nav6 {
          background: #1d9f85;
        }
        &.nav7 {
          background: #b9393f;
          .nav-item-main {
            height: auto;
            padding-top: 0;
          }
        }
        &.nav8 {
          background: #803eb1;
          .nav-item-main {
            height: auto;
            padding-top: 0;
          }
        }
        &.nav9 {
          background: #d2912f;
          height: 0.82rem;
          .nav-item-main {
            height: auto;
            padding-top: 0;
          }
          .nav-icon {
            width: 0.4rem;
            height: 0.4rem;
          }
        }
        &.nav10 {
          background: #69b145;
          height: 0.82rem;
          .nav-item-main {
            height: auto;
            padding-top: 0;
          }
          .nav-icon {
            width: 0.4rem;
            height: 0.4rem;
          }
        }
        &.nav11 {
          background: #4bbba8;
          height: 0.82rem;
          .nav-item-main {
            height: auto;
            padding-top: 0;
          }
          .nav-icon {
            width: 0.4rem;
            height: 0.4rem;
          }
        }
        .nav-icon {
          display: block;
          width: 0.65rem;
          height: 0.65rem;
          margin-right: 0.1rem;
          margin-left: 0.1rem;
        }
        .nav-item-main {
          height: 100%;
          display: block;
          padding-top: 0.16rem;
          .nav-title {
            font-size: 0.2rem;
            font-weight: bold;
          }
          .nav-desc {
            margin-top: 0.1rem;
            font-size: 0.12rem;
            line-height: 0.2rem;
          }
        }
      }
    }
  }

  .nav-items {
    display: flex;
    .nav-item {
      flex: 1;
      background: #fff;
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      padding: 0.2rem 0;
      & + .nav-item {
        margin-left: 0.2rem;
      }
      .nav-icon {
        width: 0.6rem;
      }
      .nav-title {
        color: #c94c49;
        font-size: 0.3rem;
        margin-top: 0.2rem;
        font-weight: bold;
      }
    }
  }

  .waist {
    display: block;
    height: 0.83rem;
    // background-image: linear-gradient(to right, #73E673 , #36B336);
    background: rgb(223, 73, 74);
    text-align: center;
    line-height: 0.83rem;
    font-size: 0.32rem;
    color: #fff;
    font-weight: bold;
    border-radius: 0.08rem;
    margin: 0.1rem 0;
  }

  .link-list {
    display: flex;
    width: 100%;
    flex-wrap: wrap;
    justify-content: space-between;
    .link-item {
      text-align: center;
      background: white;
      margin-top: 0.1rem;
      display: flex;
      align-items: center;
      justify-content: center;
      width: 24%;
      height: 50px;
      overflow: hidden;
      border-radius: 6px;
      &:nth-child(2n) {
        margin-left: 0.1rem;
      }
      a {
        color: #000;
        display: block;
        width: 100%;
        height: 100%;
      }
      .linkImg {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
      }
    }
  }
  .artice-module {
    display: flex;
    justify-content: space-between;
    .newspaper {
      width: 100%;
      &.fullscreen {
        height: 100%;
      }
      // &.rightitem{
      //   height: 2.86rem;
      // }
    }
    .left-newspaper {
      width: 50%;
    }
    .right-artice {
      width: 50%;
      margin-left: 0.1rem;
    }

    .artice-list {
      padding-top: 0.2rem;
      .artice-item {
        font-size: 0.16rem;
        line-height: 0.24rem;
        color: #000;
        width: 100%;
        padding: 0.07rem 0.1rem;
        border: 1px solid #cccccc;
        border-radius: 0.04rem;
        background: white;
        & + .artice-item {
          margin-top: 0.3rem;
        }
        .artice-time {
          font-size: 0.14rem;
          line-height: 0.2rem;
        }
        a {
          color: #000;
        }
      }
    }

    // .link-list{
    //   display: flex;
    //   width: 100%;
    //   flex-wrap: wrap;
    //   justify-content: space-between;
    //   .link-item{
    //     width: calc(50% - .05rem);
    //     height: .4rem;
    //     text-align: center;
    //     line-height: .4rem;
    //     font-size: .2rem;
    //     color: #000;
    //     background: #ededed;
    //     margin-top: .1rem;
    //     &:nth-child(2n){
    //       margin-left: .1rem;
    //     }
    //     a{
    //       color: #000;
    //     }
    //   }
    // }
  }
}
</style>